﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Cocktails : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        int itemsperrow = 3;

        Label1.Text = (String)Session["TableID"];
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        DataTable dt = dv.Table;
        DataRowCollection drc = dt.Rows;
        int nbrOfDishes = drc.Count;
        TableRow tr = null;
        int count =0;

        foreach (DataRow r in drc)
        {
            //Current row in the table will hold info from current data row r
            if (count % itemsperrow == 0)
            {
                tr = new TableRow();
            } 
            //Create a first cell in current row to hold the image
            TableCell c = new TableCell();
            Image img = new Image();
            img.ImageUrl = (String)r["Image"];
            img.AlternateText = ((String)r["Image"]) + " can't find it";
            //Add Image to cell
            c.Controls.Add(img);
            String myLiteral = "<p>" + "Name: " + ((String)r["DishName"]) + "</br></br>";
            myLiteral = myLiteral + "Description: " + ((String)r["DishDescription"]) + "</br></br>";
            myLiteral = myLiteral + "Price: " + ((int)r["Price"]).ToString() +" SR"+ "</br>";
            myLiteral = myLiteral + "<a href=\"./ViewOrder.aspx?dish=" + ((String)r["DishName"]) + "\">Order</a> </p>";
            c.Controls.Add(new LiteralControl(myLiteral));
            //Add cell to table
            tr.Cells.Add(c);

            //Create second cell in current row to hold description and Order to click
            /*TableCell c2 = new TableCell();
            Image img1 = new Image();
            img1.ImageUrl = (String)r["Image"];
            img1.AlternateText = ((String)r["Image"]) + " can't find it";
            //Add Image to cell
            c2.Controls.Add(img1);
            String myLiteral1 = "<p>" + "Name: " + ((String)r["DishName"]) + "</br></br>";
            myLiteral1 = myLiteral1 + "Description: " + ((String)r["DishDescription"]) + "</br></br>";
            myLiteral1 = myLiteral1 + "Price: " + ((int)r["Price"]).ToString() + "</br>";
            myLiteral1 = myLiteral1 + "<a href=\"./ViewOrder.aspx?dish=" + ((String)r["DishName"]) + "\">Order</a> </p>";
            c2.Controls.Add(new LiteralControl(myLiteral));
            //Add cell to table
            //new LiteralControl("<a href='./Images/dish1.png'>dish1</a>"));
            tr.Cells.Add(c2);
            */
            if (count % itemsperrow == (itemsperrow - 1)) { 
             Table1.Rows.Add(tr);
            }
            count++;
                      // Table1.CssClass = "CSSTableGenerator";

        }
        //in case you dnt have any items in the last row : add count!=0 & this condition using or
        if (count != 0 || ((count % itemsperrow) != 1))
            Table1.Rows.Add(tr);

        Table1.Attributes.Add("Width", "750");


    }
}